package cn.lanqiao.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.lanqiao.common.annotation.Log;
import cn.lanqiao.common.core.controller.BaseController;
import cn.lanqiao.common.core.domain.AjaxResult;
import cn.lanqiao.common.enums.BusinessType;
import cn.lanqiao.business.domain.GroupsManagement;
import cn.lanqiao.business.service.IGroupsManagementService;
import cn.lanqiao.common.utils.poi.ExcelUtil;
import cn.lanqiao.common.core.page.TableDataInfo;

/**
 * 小组信息Controller
 * 
 * @author zongzi
 * @date 2024-07-08
 */
@RestController
@RequestMapping("/business/groups_management")
public class GroupsManagementController extends BaseController
{
    @Autowired
    private IGroupsManagementService groupsManagementService;

    /**
     * 查询小组信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:groups_management:list')")
    @GetMapping("/list")
    public TableDataInfo list(GroupsManagement groupsManagement)
    {
        startPage();
        System.out.println(groupsManagement.getClassName());
        List<GroupsManagement> list = groupsManagementService.selectGroupsManagementList(groupsManagement);
        return getDataTable(list);
    }

    /**
     * 导出小组信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:groups_management:export')")
    @Log(title = "小组信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GroupsManagement groupsManagement)
    {
        List<GroupsManagement> list = groupsManagementService.selectGroupsManagementList(groupsManagement);
        ExcelUtil<GroupsManagement> util = new ExcelUtil<GroupsManagement>(GroupsManagement.class);
        util.exportExcel(response, list, "小组信息数据");
    }

    /**
     * 获取小组信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:groups_management:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(groupsManagementService.selectGroupsManagementById(id));
    }

    /**
     * 新增小组信息
     */
    @PreAuthorize("@ss.hasPermi('business:groups_management:add')")
    @Log(title = "小组信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GroupsManagement groupsManagement)
    {
        return toAjax(groupsManagementService.insertGroupsManagement(groupsManagement));
    }

    /**
     * 修改小组信息
     */
    @PreAuthorize("@ss.hasPermi('business:groups_management:edit')")
    @Log(title = "小组信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GroupsManagement groupsManagement)
    {
        return toAjax(groupsManagementService.updateGroupsManagement(groupsManagement));
    }

    /**
     * 删除小组信息
     */
    @PreAuthorize("@ss.hasPermi('business:groups_management:remove')")
    @Log(title = "小组信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(groupsManagementService.deleteGroupsManagementByIds(ids));
    }

    /**
     * 通过班级id获取小组信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:groups_management:query')")
    @GetMapping(value = "/getListByClassId")
    public AjaxResult getListByClassId(@PathVariable("classId") Long classId)
    {
        return success(groupsManagementService.selectGroupsManagementsByClassId(classId));
    }
}
